<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Create Teamwork Peer Evaluation</title>
</head>
<body>
<pre>
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/Classes/PHPExcel.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/Classes/PHPExcel/Writer/Excel2007.php';

//Create new Excel object
$objPHPExcel = new PHPExcel();
$nSheetCount = 0;

//	set cell style
$aDefaultBorder = array(
    'style' => PHPExcel_Style_Border::BORDER_THIN,
    'color' => array('rgb'=>'000000')
);

$aExcelStyle = array(
	'border'=>array(
		'allborders' => $aDefaultBorder
    ),
	'fill' => array(
        'type' => PHPExcel_Style_Fill::FILL_SOLID,
        'color' => array('rgb'=>'E1E1E1'),
    )
);

include "db.conf.php";
$sTableName="2014_w_cal";

$sqlConnect = new mysqli($sServer,$sUser,$sPassword,$sDatabaseName);
$sqlConnect->query("SET NAMES 'UTF8'");

for ($nTeam=1;$nTeam<15;$nTeam++)
{
	//	setting up a new sheet
	if ($nSheetCount>0)
		{
			//create next sheet
			$objPHPExcel->createSheet();
			$objPHPExcel->setActiveSheetIndex($nSheetCount);
		}
	$objActiveSheet=$objPHPExcel->getActiveSheet();
	//	Add label 
	$objActiveSheet->setTitle("T".$nTeam);
	
	//	Set headings
	$objActiveSheet->setCellValue("A1","Name");
	$objActiveSheet->setCellValue("B1","Percent");
	
	//	Begin adding members	
	//	reset row number
	$row=2;	
	
	//	query
	$sQuery = "select `name` from `".$sTableName."` where `team`=".$nTeam." order by `name` asc";
	
	$aTeamData =[];
	$sqlResult = $sqlConnect -> query($sQuery);
	while ($aStudentInfo = $sqlResult->fetch_array(MYSQLI_ASSOC))
	{
		$objPHPExcel->getActiveSheet()->setCellValue("A".$row,$aStudentInfo["name"]);
		$row++;
	}
	//	apply column width
	$objActiveSheet->getColumnDimension('B')->setAutoSize(true);
	
	//	apply style
	$objActiveSheet->getStyle("A1:B".($row-1))->applyFromArray($aExcelStyle);
	
	// increase Sheet Count
	$nSheetCount++;
	//print_r($aTeamData);
}
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');

$objWriter->save("TeamEvaluation.xlsx");
?>
</pre>
</body>
</html>